package studychinese.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.activity.BaseActivity;
import com.hschinese.pronunciation.interfaces.OnItermClickLisenner;
import com.jaeger.library.StatusBarUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import studychinese.adapters.StrokesAdapter;
import studychinese.adapters.WordAdapter;

/**
 * Created by buba on 2018/2/5.
 */

public class StrokesListActivity extends BaseActivity implements View.OnClickListener, OnItermClickLisenner {
    /*  @Bind(R.id.iv_back)
      ImageView ivBack;*/
    @Bind(R.id.rv_base)
    RecyclerView rvBase;
    @Bind(R.id.rv_complex)
    RecyclerView rvComplex;
    /*    @Bind(R.id.iv_title)
        ImageView ivTitle;*/
    @Bind(R.id.ll_back)
    LinearLayout ll_back;
    @Bind(R.id.iv_title)
    ImageView ivTitle;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    private String[] baseStr = {"儿", "二", "十", "人", "小", "月", "目", "回"};
    private String[] complexStr = {"一", "心", "二", "三", "五", "手", "车", "年", "上", "人", "八", "个", "儿", "九", "七", "开", "关", "羊", "牛", "午", "十", "木", "米", "六", "天", "元", "大", "飞", "太", "下", "我", "小", "少", "山", "水", "东", "乐", "口", "日", "月", "目", "四", "石", "西", "白", "雨", "再", "本", "子", "女", "马"};
    private int[] baseRes = {R.drawable.bihua_h, R.drawable.bihua_s, R.drawable.bihua_p, R.drawable.bihua_n, R.drawable.bihua_t, R.drawable.bihua_d};
    private int[] complexRes = {R.drawable.bihua_hg, R.drawable.bihua_hp, R.drawable.bihua_hz, R.drawable.bihua_hzz, R.drawable.bihua_hzzz, R.drawable.bihua_hzt, R.drawable.bihua_hzg, R.drawable.bihua_hzzg, R.drawable.bihua_hpg, R.drawable.bihua_hpwg, R.drawable.bihua_hzzwg, R.drawable.bihua_hzzp, R.drawable.bihua_sz, R.drawable.bihua_szz, R.drawable.bihua_st, R.drawable.bihua_sg, R.drawable.bihua_swg, R.drawable.bihua_szwg, R.drawable.bhua_pz, R.drawable.bihua_wg};
    /**
     * type_page =1 ,笔画，type_page = 2，笔顺
     */
    private int type_page;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        setContentView(R.layout.activity_strokes_list);
        ButterKnife.bind(this);
        innitView();
    }


    @Override
    protected void setStatusBar() {
        StatusBarUtil.setTranslucentForImageView(this, 0, ll_back);
    }

    private void innitView() {
        type_page = getIntent().getIntExtra("type", 1);
        if (type_page == 1) {
            ivTitle.setImageResource(R.drawable.title_bihua);
        } else {
            ivTitle.setImageResource(R.drawable.title_bishun);
        }
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        GridLayoutManager gridLayoutManagerBase = new GridLayoutManager(this, 4) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        GridLayoutManager gridLayoutManagerComplex = new GridLayoutManager(this, 4) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        rvBase.setLayoutManager(gridLayoutManagerBase);
        rvComplex.setLayoutManager(gridLayoutManagerComplex);
        rvBase.setFocusableInTouchMode(false);
        rvComplex.setFocusableInTouchMode(false);
        if (type_page == 2) {
            WordAdapter wordAdapterBase = new WordAdapter(this, baseStr, 1, this);
            WordAdapter wordAdapterComplex = new WordAdapter(this, complexStr, 2, this);
            rvBase.setAdapter(wordAdapterBase);
            rvComplex.setAdapter(wordAdapterComplex);
        } else if (type_page == 1) {
            StrokesAdapter strokesAdapterBase = new StrokesAdapter(this, baseRes, 1, this);
            StrokesAdapter strokesAdapterComplex = new StrokesAdapter(this, complexRes, 2, this);
            rvBase.setAdapter(strokesAdapterBase);
            rvComplex.setAdapter(strokesAdapterComplex);
        }
    }

    @Override
    public void onClick(View view) {
        finish();
    }

    @Override
    public void onClick(int position, int type) {
        if (type_page == 1) {//笔画部分
            if (type == 1) {//是上面的演示部分
                startActivity(new Intent(StrokesListActivity.this, BaseStrokesShowActivity.class).putExtra("position", position));
            } else if (type == 2) {//下面的画
                startActivity(new Intent(StrokesListActivity.this, ComplexStrokesActivity.class).putExtra("position", position));
            }
        } else if (type_page == 2) {//笔顺部分
            if (type == 1) {//是上面的演示部分
                startActivity(new Intent(StrokesListActivity.this, BaseWordShowActivity.class).putExtra("position", position));
            } else if (type == 2) {//下面的画
                startActivity(new Intent(StrokesListActivity.this, ComplexWordActivity.class).putExtra("position", position));
            }
        }

    }


}
